import Foundation

protocol MPConvertibleData {}
extension NSData: MPConvertibleData {}
extension Data: MPConvertibleData {}

func mp_data(_ value: Any, type: Any.Type) -> MPConvertibleData? {
    var data: Data?
    if let str = value as? String {
        data = str.data(using: .utf8)
    } else {
        data = value as? Data
    }
    guard let v = data else { return nil }
    return type is NSMutableData.Type ? NSMutableData(data: v) : v
}
